/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.classdiagram.helper;

import org.eclipse.uml2.uml.BehavioredClassifier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.FunctionBehavior;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.UMLPackage;

import com.cea.papyrus.core.helper.NodeHelper;
import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * Factory that can create and delete an {@link org.eclipse.uml2.uml.FunctionBehavior}.
 */
public class NodeFunctionBehaviorHelper extends NodeHelper {

	///////////////////////////////////////////////////////////////////////////
	// UML Management
	///////////////////////////////////////////////////////////////////////////

	/**
	 * {@inheritDoc} 
	 */
	@Override
	public  org.eclipse.uml2.uml.FunctionBehavior createUMLElement(String name, org.eclipse.uml2.uml.Element umlParent){
		Debug.debug(this,"Call NodeClassFactory.createElement()", channel); //$NON-NLS-1$
		org.eclipse.uml2.uml.FunctionBehavior umlFunctionBehavior;
		if (umlParent instanceof Package) {
			umlFunctionBehavior=(FunctionBehavior)((Package)umlParent).createOwnedType(name, UMLPackage.eINSTANCE.getFunctionBehavior());
			return umlFunctionBehavior;
		} else if (umlParent instanceof BehavioredClassifier) {
			umlFunctionBehavior=(FunctionBehavior)((BehavioredClassifier)umlParent).createOwnedBehavior(name, UMLPackage.eINSTANCE.getFunctionBehavior());
			return umlFunctionBehavior;
		}
		return null;

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean canCreateUMLElement(Element umlParent) {
		if(umlParent instanceof Package || umlParent instanceof BehavioredClassifier) {
			return true;
		}
		return false;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean addUMLElement(Element element, Element umlParent) {
		if(umlParent instanceof Package) {
			return ((org.eclipse.uml2.uml.Package)umlParent).getPackagedElements().add((PackageableElement)element);
		}
		if(umlParent instanceof BehavioredClassifier) {
			return ((BehavioredClassifier)umlParent).getOwnedBehaviors().add((FunctionBehavior)element);
		}
		return false;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean removeUMLElement(Element element, Element umlParent) {
		// Added by A. Lanusse for removing elt from component
		if(umlParent instanceof BehavioredClassifier) {
			return ((org.eclipse.uml2.uml.BehavioredClassifier)umlParent).getOwnedBehaviors().remove(element);
		}
		if(umlParent instanceof Package) {
			return ((Package)umlParent).getPackagedElements().remove(element);
		}
		return false;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getBaseString() {
		return "FunctionBehavior_"; //$NON-NLS-1$
	}

}
